#!/usr/bin/python

# svg2csv.py

from __future__ import division

import os.path
from optparse import OptionParser

from ot_simulator.template import svg_to_csv

def run():
    parser = \
      OptionParser(
        usage="usage: %prog [options] x_start x_end "
                      "svg_filename [csv_filename]",
        description="""x_start and x_end are the min and max values for X.  
The values in the svg file are scaled and offset to produce csv X 
values in this range.  The same scale factor is applied to the csv Y values,
but the Y values are not offset to start or end at some magic value.  You can
do that later with a spreadsheet, once you find out what the range of Y values
are.""",
        version= '%prog 0.1.0',
        )
    parser.add_option("-s", "--x-spacing", type="float",
                      default=0.01,
                      help="the difference in X between two adjacent values: "
                           "default 0.01")

    (options, args) = parser.parse_args()

    if len(args) < 3 or len(args) > 4:
        parser.error("incorrect number of arguments")

    x_start = float(args[0])
    x_end = float(args[1])
    svg_filename = args[2]

    if len(args) == 4:
        csv_filename = args[3]
    else:
        csv_filename = os.path.splitext(svg_filename)[0] + '.csv'

    svg_to_csv.svg_to_csv(svg_filename, csv_filename, x_start, x_end, 
                          options.x_spacing)

if __name__ == "__main__":
    run()

